<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
        暴力法，遍历nums数组，然后找出子数组中的最大值。leedcode中会超时
        */
      var maxSlidingWindow = function (nums, k) {
        let result = []
        for (let i = 0; i < nums.length; i++) {
          if (i + k > nums.length) {
            break
          }
          let arr = nums.slice(i, i + k)
          result.push(max(arr))
        }
        return result
        function max(arr) {
          let n = arr[0]
          for (let i = 0; i < arr.length; i++) {
            if (arr[i] >= n) {
              n = arr[i]
            }
          }
          return n
        }
      }
      maxSlidingWindow([1, 3, -1, -3, 5, 3, 6, 7], 3)
    </script>
  </body>
</html>
